DEPARTMENT OF INFORMATION TECHNOLOGY RECORD NOTE BOOK 2019 – 2020 UD1ITCA – PYTHON PROGRAMMING LAB. NAME OF THE STUDENT : REGISTER NUMBER : DEPARTMENT : YEAR : SEMESTER : BONA FIDE CERTIFICATE Name : ....................................... Reg. No : ....................................... Branch : ....................................... Certified that this is the bonafide record of work done by the above student i n the ................................................................... ............................... laboratory during the year 2020 Head of the Department Lab in - Charge Submitted for the practical examination held on ........................... Internal Examiner External Examiner CONTENTS S .no Date of experiment Name of the experiment Page no Signature 1 10.1.20 STUDY EXPERIMENT – PYTHON PROGRAMMING ENVIRONMENT 2 17.1.20 VARIABLES AND TYPE CONVERSION 3 24.1.20 PROBLEM INVOLVING IN IF - THEN - ELSE STRUCTURE 4 31.1.20 OPERATORS AND EXPRESSIONS 5 07.2.20 FUNCTIONS 6 14.2.20 LOGIN VALIDATION USING FUNCTION 7 15.2.20 LIST OPERATIONS 8 21.2.20 TUPLE OPERATIONS 9 28.2.20 DICTIONARY 10 06.3.20 STRING OPERATION 11 13.3.20 EXCEPTIONAL HANDLING 12 10.4.20 COMMAND LINE ARGUMENT DATE: 10.1.20 STUDY EXPERIMENT – PYTHON PROGRAMMING ENVIRONMENT EX.NO: 01 Aim: To understand the python programming environment 1. Familiarizing with Programming environment IDLE is the standard Python development environment. Its name is an acronym for “Integrated Development Language Environment. Introduction to IDLE This is the IDLE Python Shell window . The >>> symbol is the Python Shell prompt ; it indicates that the Pytho n Shell is ready to get Python commands. This is the IDLE Python Shell window . The >>> symbol is the Python Shell prompt ; it indicates that the Python Shell is ready to get Python commands. In the IDLE Python Shell windows type the commands (statements) that Python understands. 2. Doing simple arithmetic operations in the Python Shell window. 2. Writing a simple program, saving it, and executing it. The Python Shell window are kept by the Python program (also called Python interpreter) in its main memory. Main memory is volatile. 2.1 Writing and saving a simple program To write simple program just click File in the Python Shell window and then New Wi ndow. The following window will appear: Result Thus the study experiment is completed successfully. DATE: 17.1.20 VARIABLES AND TYPE CONVERSION EX.NO: 02 Aim: Write a program to find the engineering cutoff marks using variables. Procedure: 1. Define the variables and read the values. 2. Convert the input from string to integer 3. Calculate the cutoff using mathematical expression 4. Print the result Flowchart: Program: #calculate engineering cutoff p=int(input(“enter physics marks”)) c=int(input(“enter chemistry marks”)) m=int(input(“enter maths marks”)) cutoff=(p/4+c/4+m/2) print(“cutoff =”,cutoff) Output: enter physics marks 90 enter chemistry marks 100 enter maths marks 95 cutoff = 95.0 Result: Thus the program is implemented and executed successfully DATE: 24.1.20 PROBLEM INVOLVING IN IF - THEN - ELSE STRUCTURE EX.NO: 03 Aim: Write a program to check the given number is positive or negative Procedure: 1. Define the variables and read the values 2. Convert the input from string to integer 3. Check the test condition true or false 4. Print the result Flowchart: Program: 1 num = 3 if num > 0: print(num, "is a positive number.") print("This is always printed.") num = - 1 if num > 0: print(num, "is a positive number.") print("This is also always printed.") Output: 3 is a positive number. This is always printed. This is also always printe d. Program: 2 num = 3 if num >= 0: print("Positive or Zero") else: print("Negative number") Output: Positive or Zero Result: Thus the program is executed successfully DATE: 31.1.20 OPERATORS AND EXPRESSIONS EX.NO: 04 Aim Write a python program to solve expression the following expression using python Algorithm: 1. Define the variables 2. Implement the arithmetic expression 3. Evaluate the expressions 4. Print the result Flowchart: Expression: #Arithmetic operator a=10 b=5 print("a+b=",a+b) print("a - b=",a - b) print("a*b=",a*b) print("a/b=",a/b) print("a%b=",a%b) print("a//b=",a//b) print("a**b=",a**b) # Comparison operator a=10 b=5 print("a>b=>",a>b) print("a>b=>",a<b) print("a==b=>",a==b) print("a!=b=>",a!=b) print("a>=b=>",a<=b) print("a>=b=>",a>=b) # Identity operator x = 5 y = 5 x2 = 'Hello' y2 = 'Hello' print(x1 is not y1) print(x2 is y2) #membership operator to s earch an item from list x=[5,3,6,4,1] a=input(“Search an item in list”) print(“The given item in list”,a in x ) print(“The given item in list”,a not in x ) Output: a+b= 15 a - b= 5 a*b= 50 a/b= 2.0 a%b= 0 a//b= 2 a**b= 100000 a>b=> True a>b=> False a==b=> False a!=b=> True a>=b=> False a>=b=> True False True Search an item in list Result: Thus the program is implemented and executed successfully DATE: 07.2.20 FUNCTIONS EX.NO: 05 Aim: Write a program to swap two number using function Procedure: 1. Define the function with parameters 2. Keyword def that marks the start of the function header 3. Assign the value to the function call 4. Call the function using function call 5. Print the result Flowchart: Program: def swap_numbers(a, b): temp = a a = b b = temp print("After Swapping two Number: num1 = {0} and num2 = {1}".format(a, b)) num1 = float(input(" Please Enter the First Value : ")) num2 = float(input(" Please Enter the Second Value : ")) print("Before Swapping two Number: num1 = {0} and num2 = {1}" .format(num1, num2)) swap_numbers(num1, num2) Output: Please Enter the First Value : 100 Please Enter the Second Value : 200 Before Swapping two Number: num1 = 100.0 and num2 = 200.0 After Swapping two Number: num1 = 200.0 and num2 = 100.0 Result: Thus the program is implemented and executed successfully DATE: 14.2.20 LOGIN VALIDATION USING FUNCTION EX.NO: 06 Aim: Write a program to implement the login validation using function Procedure: 1. Define the function to pass username and password 2. Read the username and password 3. Check the username and password 4. Print the login status 5. Print the result Flowchart: Program: def login_check(uname,pname): if uname=="amet" and pname=="Amet123": display="we lcome",uname else: display="Incorrect Username and password" return display print("Welcome user for login") username=input("Enter your username :") password=input("Enter your passwork :") print(login_check(username,password)) Output: Welcome user for login Enter your username :amet Enter your passwork :Amet123 ('welcome', 'amet') Result: Thus the program is implemented and executed successfully DATE: 15.2.20 LIST OPERATIONS EX.NO: 07 Aim: Write a program to perform list operations Procedure: 1. Create a list with values 2. Perform accessing the list using list index 3. Assign the value to list using assignment operators 4. Similarly perform delete, slicing 5. Perform comprehension to iterate the value from list 6. Print the result Program: #Accessing the item from list '''list1 = ['phys ics', 'chemistry', 1997, 2000]; list2 = [1, 2, 3, 4, 5, 6, 7 ]; print ("list1[0]: ", list1[2]) print ("list2[1:5]: ", list2[1:5]) ''' '''# update the list list = ['physics', 'chemistry', 1997, 2000]; print ("Value available at index 2 : ") print (list[2]) list[2] = 2001; print ("New value available at index 2 : ") print (list[2]) ''' # delete list ''' list1 = ['physics', 'chemistry', 1997, 2000]; print (list1) del (list1[2]) print ("After deleting value at index 2 : ") print (list1) ''' # slicing the list list = ['p','r','o','g','r','a','m'] # elements 3rd to 5th ''' print(my_list[2:5]) # elements beginning to 4th print(my_list[: - 5]) # elements 6th to end print(my_list[5:]) # elements beginning to end print(my_list[:]) ''' # Comprehension list = [] for x in range(10): list.append(x) print (list) Output: list1[0]: 1997 list2[1:5]: [2, 3, 4, 5] Value available at index 2 : 1997 New value available at index 2 : 2001 ['physics', 'chemistry', 1997, 2000] After deleting value at index 2 : ['physics', 'chemistry', 2000] Result: Thus the program is implemented and executed successfully